package com.it.controller;/**
 * @ClassName EsController
 * @Description: TODO
 * @Author gejianhao
 * @Date 2019/7/29
 * @Version V1.0
 **/

import com.it.entity.Student;
import com.it.service.ElasticSearchService;
import org.elasticsearch.action.update.UpdateRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
 * @ClassName EsController
 * @Description: es的api类
 * @Author gejianhao
 * @Date 2019/7/29
 * @Version V1.0
 **/
@Controller
public class EsController {

    @Autowired
    private ElasticSearchService esService;


    @RequestMapping("/add")
    public @ResponseBody
    String addEs() {
        Student stu = new Student();
        stu.setAddress("地址");
        stu.setName("姓名");
        stu.setSex(1);
        return esService.add(stu);
    }

    @RequestMapping("/queryById")
    public @ResponseBody
    Map<String, Object> queryById(String id) {
        return (Map<String, Object>) esService.queryById(id);
    }

    @RequestMapping("/delete")
    public @ResponseBody
    String delete(String id) {
        return esService.delete(id);
    }

    @RequestMapping("/update")
    public @ResponseBody
    String update(String id) throws InterruptedException, ExecutionException {
        Student stu = new Student();
        stu.setAddress("地址1");
        stu.setName("姓名1");
        stu.setSex(0);
        return esService.update(id, stu);
    }

    @RequestMapping("/queryBoolPageSize")
    public @ResponseBody
    List<Map<String, Object>> boolquery(int currentPage, int pageSize) {
        return esService.boolquery(currentPage,pageSize);
    }
}
